############################################################################
# CMakeLists.txt
# author:suka
# create:2020.10.1
############################################################################

find_program(ANDROID_NDK_BUILD_PROGRAM ndk-build ndk-build.cmd HINTS $ENV{ANDROID_NDK})
if(NOT ANDROID_NDK_BUILD_PROGRAM)
	message(FATAL_ERROR "Cannot find 'ndk-build', make sure you installed the NDK and added it to your PATH ANDROID_NDK=$ENV{ANDROID_NDK}")
endif()
message(STATUS "ANDROID_NDK_BUILD_PROGRAM=${ANDROID_NDK_BUILD_PROGRAM}")
get_filename_component(CMAKE_ANDROID_NDK "${ANDROID_NDK_BUILD_PROGRAM}" DIRECTORY)

set(CMAKE_SYSTEM_NAME "Android")
if(NOT CMAKE_ANDROID_API)
	set(CMAKE_ANDROID_API 21)
endif()
#set(CMAKE_ANDROID_STL_TYPE "gnustl_shared")
#set(CMAKE_ANDROID_STL_TYPE "c++_shared")

set(CMAKE_FIND_ROOT_PATH "${CMAKE_SYSROOT}" "${CMAKE_INSTALL_PREFIX}")
# search for programs in the build host directories
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
# for libraries and headers in the target directories
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)

set(CMAKE_CXX_FLAGS_RELEASE "-Os -DNDEBUG")
set(CMAKE_C_FLAGS_RELEASE "-Os -DNDEBUG")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-Os -g -DNDEBUG")
set(CMAKE_C_FLAGS_RELWITHDEBINFO "-Os -g -DNDEBUG")

if(ENABLE_CPPCHECK)
    find_program(CMAKE_C_CPPCHECK NAMES cppcheck)
    if(CMAKE_C_CPPCHECK)
        list(
            APPEND CMAKE_C_CPPCHECK
                "--enable=warning"
                "--enable=style"
                "--enable=performance"
                "--enable=portability"
                "--enable=information"
                "--inconclusive"
                "--force"
                "--inline-suppr"
                "--std=posix"
        )
    else()
        message(FATAL_ERROR "Require cppcheck for static analysis.")
    endif()
endif()
